﻿using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Collections.Generic;
using UnityEngine;
using MainScene;
using Sirenix.OdinInspector;

/// <summary>
/// Command data.
/// 事件类型参数( 具体操作 )
/// </summary>
namespace MainScene.Evt.Command
{
    [Serializable]
    [XmlInclude(typeof(PlayPlotCommandData))]
    [XmlInclude(typeof(SetUnitAutoMoveData))]
    [XmlInclude(typeof(ActionCommandData))]
    [XmlInclude(typeof(ChangeToFixCameraCommandData))]
    [XmlInclude(typeof(ChangeCameraTargetCommandData))]
    [XmlInclude(typeof(ChangeUnitAICommandData))]
    [XmlInclude(typeof(SetFieldOfViewCommandData))]
    [XmlInclude(typeof(SetObjectVisibleCommandData))]
    [XmlInclude(typeof(SetOrientationCommandData))]
    [XmlInclude(typeof(SetPositionCommandData))]
    [XmlInclude(typeof(SetUnitAIActiveCommandData))]
    [XmlInclude(typeof(ShowTalkCommandData))]
    [XmlInclude(typeof(ActiveTriggerCommandData))]
    [XmlInclude(typeof(BeginOneFightData))]
    [XmlInclude(typeof(SetEffectCommandData))]
    [XmlInclude(typeof(ChangeToFixTargetOffsetCommondData))]
    [XmlInclude(typeof(DelateStoryCommandData))]
    [XmlInclude(typeof(HideLoadingPanelData))]
    [XmlInclude(typeof(SetSliderCommandData))]
    [XmlInclude(typeof(JumpCommandData))]
    [XmlInclude(typeof(RaidEndCellData))]
    [XmlInclude(typeof(PlaySceneEffectData))]
    [XmlInclude(typeof(AnimatorStateData))]
    [XmlInclude(typeof(ChangeUIConditionLabData))]
    [XmlInclude(typeof(HideSenceGameObjectData))]
    [XmlInclude(typeof(SetRotateSceneObjData))]
    [XmlInclude(typeof(PlayEffectBoneData))]
    [TypeConverterAttribute(typeof(ExpandableObjectConverter))]
    public abstract class CommandData 
    {
        [XmlAttribute("delayTime")]
        public float delayTime;
        [XmlIgnore]
        public EvtCommandType commandType { get; protected set; }
    }

    /// <summary>
    /// 自动寻路到某个点
    /// </summary>
    [Serializable]
    public class SetUnitAutoMoveData : CommandData
    {
        /// <summary>
        /// 作用物体
        /// </summary>
        [XmlAttribute("unitName")]
        public string unitName;

        /// <summary>
        /// 目标路径点
        /// </summary>
        [XmlAttribute("pathNodeName")]
        public string pathNodeName;

        [XmlAttribute("isRun")]
        public bool isRun = true;

        [XmlAttribute("moveSpeed")]
        public float moveSpeed = 0;
        [XmlAttribute("anim")]
        public string anim = "run";
        public SetUnitAutoMoveData()
        {
            commandType = EvtCommandType.SetUnitAutoMove;
            unitName = string.Empty;
            pathNodeName = string.Empty;
        }
    }

    /// <summary>
    /// 开启一场战斗
    /// </summary>
    [Serializable]
    public class SceneNPCBattleFightData : CommandData
    {
        /// <summary>
        /// 开启一场战斗的唯一怪群Id
        /// </summary>
        [XmlAttribute("targetId")]
        public int targetId;
        [XmlAttribute("taskId")]
        public int taskId;
        public SceneNPCBattleFightData()
        {
            commandType = EvtCommandType.SceneNPCBattleFight;
            targetId = -1;
            taskId = -1;
        }
    }

    /// <summary>
    /// 隐藏loading条
    /// </summary>
    public class HideLoadingPanelData : CommandData
    {
        public HideLoadingPanelData()
        {
            commandType = EvtCommandType.HideLoadingPanel;
        }
    }

    /// <summary>
    /// 开启一场战斗
    /// </summary>
    [Serializable]
    public class BeginOneFightData : CommandData
    {
        /// <summary>
        /// 开启一场战斗的唯一怪群Id
        /// </summary>
        [XmlAttribute("monsterGroupId")]
        public int monsterGroupId;
        public BeginOneFightData()
        {
            commandType = EvtCommandType.BeginOneFight;
            monsterGroupId = -1;
        }
    }
    /// <summary>
    /// 角色动画播放
    /// </summary>
    [Serializable]
    public class ActionCommandData : CommandData
    {
        [XmlAttribute("unitName")]
        public string unitName;
        [XmlAttribute("actionId")]
        public string actionId;
        [XmlAttribute("finishTime")]
        public float finishTime;

        public ActionCommandData()
        {
            commandType = EvtCommandType.ActionCommand;
            unitName = string.Empty;
            actionId = string.Empty;
        }
    }
    /// <summary>
    ///切换动画状态
    /// </summary>
    [Serializable]
    public class AnimatorStateData : CommandData
    {
        [XmlAttribute("unitName")]
        public string unitName;
        [XmlAttribute("actionId")]
        public string actionId;
        [XmlAttribute("finishTime")]
        public float finishTime;
        public AnimatorStateData()
        {
            commandType = EvtCommandType.AnimatorState;
            unitName = string.Empty;
            actionId = string.Empty;
        }
    }
    /// <summary>
    /// 切换到目标点前偏移量
    /// </summary>
    [Serializable]
    public class ChangeToFixTargetOffsetCommondData : CommandData
    {
        /// <summary>
        /// 需要切换到的指定目标
        /// </summary>
        [XmlAttribute("targetId")]
        public string targetId;
        [XmlAttribute("forwardOffset")]
        public float forwardOffset;
        [XmlAttribute("heightOffset")]
        public float heightOffset;
        /// <summary>
        /// 相机的持续时间
        /// </summary>
        [XmlAttribute("duration")]
        public float duration;

        public ChangeToFixTargetOffsetCommondData()
        {
            commandType = EvtCommandType.ChangeToFixTargetOffset;
            targetId = string.Empty;
        }
    }
    /// <summary>
    /// Change to fix camera command data.
    /// 切换到固定视角摄像机
    /// </summary>
    [Serializable]
    public class ChangeToFixCameraCommandData : CommandData
    {
        /// <summary>
        /// 需要切换到的指定相机
        /// </summary>
        [XmlAttribute("cameraId")]
        public string cameraId;
        [XmlAttribute("duration")]
        public float duration;
        /// <summary>
        /// 相机的持续时间
        /// </summary>
        [XmlAttribute("flyTime")]
        public float flyTime;

        public ChangeToFixCameraCommandData()
        {
            commandType = EvtCommandType.ChangeToFixCamera;
            cameraId = string.Empty;
        }
    }


    /// <summary>
    /// 更换主相机跟随
    /// </summary>
    [Serializable]
    public class ChangeCameraTargetCommandData : CommandData
    {
        /// <summary>
        /// 空就不会跟随，可以自己配置摄像机
        /// </summary>
        [XmlAttribute("unitName")]
        public string unitName;
        public ChangeCameraTargetCommandData()
        {
            commandType = EvtCommandType.ChangeCameraTarget;
            unitName = string.Empty;
        }
    }
    [Serializable]
    public class ChangeUIConditionLabData : CommandData
    {
        [XmlAttribute("condtionId")]
        public int condtionId;

        [XmlAttribute("content")]
        public string content;
        public ChangeUIConditionLabData()
        {
            commandType = EvtCommandType.ChangeUICondtion;
            content = string.Empty;
        }
    }

    /// <summary>
    /// Change unit AI command data.
    /// 切换Unit AI
    /// </summary>
    [Serializable]
    public class ChangeUnitAICommandData : CommandData
    {
        [XmlAttribute("unitAIType")]
        public SceneUnitAI unitAIType;
        [XmlAttribute("areaId")]
        public string areaId;
        [XmlAttribute("unitName")]
        public string unitName;
        [XmlAttribute("orientation")]
        public float orientation;

        public ChangeUnitAICommandData()
        {
            commandType = EvtCommandType.ChangeUnitAI;
            unitName = string.Empty;
            areaId = string.Empty;
        }
    }


    /// <summary>
    /// Set field of view command data.
    /// 设置当前相机FOV
    /// </summary>
    [Serializable]
    public class SetFieldOfViewCommandData : CommandData
    {
        [XmlAttribute("fieldOfView")]
        public float fieldOfView;
        [XmlAttribute("duration")]
        public float duration;

        public SetFieldOfViewCommandData()
        {
            commandType = EvtCommandType.SetFieldOfView;
        }
    }

    /// <summary>
    /// 播放slider
    /// </summary>
    [Serializable]
    public class SetSliderCommandData : CommandData
    {
        [XmlAttribute("unitName")]
        public string text;
        [XmlAttribute("durationTime")]
        public float durationTime;
        public SetSliderCommandData()
        {
            commandType = EvtCommandType.SliderCell;
            text = string.Empty;
        }

    }
    /// <summary>
    /// 播放场景特效
    /// </summary>
    [Serializable]
    public class PlaySceneEffectData : CommandData
    {
        [XmlAttribute("EffectAnchor")]
        public string EffectAnchor;
        [XmlAttribute("SceneEffectId")]
        public int SceneEffectId;
        public PlaySceneEffectData()
        {
            commandType = EvtCommandType.PlaySceneEffect;
            EffectAnchor = string.Empty;
        }
    }

    [Serializable]
    public class PlayEffectBoneData : CommandData
    {
        [XmlAttribute("Add_True_Remove_false")]
        public bool Add_True_Remove_false;
        [XmlAttribute("sceneRoot")]
        public string sceneRoot;
        [XmlAttribute("Bone")]
        public string Bone;
        [XmlAttribute("effectpath")]
        public string effectpath;
        public PlayEffectBoneData()
        {
            commandType = EvtCommandType.PlayEffectBone;
            Add_True_Remove_false = true;
            sceneRoot = string.Empty;
            effectpath = string.Empty;
            Bone = string.Empty;
        }
    }

    /// <summary>
    /// 设置特效
    /// </summary>
    [Serializable]
    public class SetEffectCommandData : CommandData
    {
        [XmlAttribute("unitName")]
        public string unitName;
        [XmlAttribute("effectId")]
        public int effectId;
        [XmlAttribute("useDelateDuration")]
        public bool useDelateDuration = false;
        [XmlAttribute("durationTime")]
        public float durationTime;
        public SetEffectCommandData()
        {
            commandType = EvtCommandType.PlayEffect;
            unitName = string.Empty;
        }
    }

    [Serializable]
    public class HideSenceGameObjectData : CommandData
    {
        public List<string> objectList;
        [XmlAttribute("visible")]
        public bool visible;
        public HideSenceGameObjectData()
        {
            commandType = EvtCommandType.HideSceneGameObject;
            visible = false;
            objectList = new List<string>();
        }
    }

    /// <summary>
    /// Set object visible command data.
    /// 设置物件显隐
    /// </summary>
    [Serializable]
    public class SetObjectVisibleCommandData : CommandData
    {
        [XmlAttribute("objectId")]
        public string objectId;
        [XmlAttribute("visible")]
        public bool visible;
        [XmlAttribute("isCanMoveDoor")]
        public bool isCanMoveDoor;
        public List<string> objectList;
        public SetObjectVisibleCommandData()
        {
            commandType = EvtCommandType.SetObjectVisible;
            objectId = string.Empty;
            objectList = new List<string>();
        }
    }
    //[Serializable]
    //public class XmlVec3
    //{
    //    public float x;
    //    public float y;
    //    public float z;
    //    public XmlVec3(float x, float y, float z)
    //    {
    //        this.x = x;
    //        this.y = y;
    //        this.z = z;
    //    }
    //    public Vector3 vec3()
    //    {
    //        return new Vector3(x, y, z);
    //    }
    //}
    /// <summary>
    /// 设置个体方向
    /// </summary>
    [Serializable]
    public class SetOrientationCommandData : CommandData
    {
        [XmlAttribute("unitName")]
        public string unitName;

        [XmlAttribute("lookAtMainRole")]
        public bool lookAtMainRole;
        [XmlAttribute("playerRotateToo")]
        public bool playerRotateToo = true;

        [XmlAttribute("orientation")]
        public float orientation;
        [XmlAttribute("targetNpc")]
        public string targetNpc;
        [XmlAttribute("useRoate")]
        public bool useRoate = false;
        [XmlAttribute("x")]
        public float x;
        [XmlAttribute("y")]
        public float y;
        [XmlAttribute("z")]
        public float z;
        public SetOrientationCommandData()
        {
            commandType = EvtCommandType.SetOrientation;
            unitName = string.Empty;
            targetNpc = string.Empty;
            playerRotateToo = true;
        }
    }
    /// <summary>
    /// 副本结束事件
    /// </summary>
    [Serializable]
    public class RaidEndCellData : CommandData
    {
        public RaidEndCellData()
        {
            commandType = EvtCommandType.RaidEndCell;
        }
    }
    /// <summary>
    /// 跳跃
    /// </summary>
    [Serializable]
    public class JumpCommandData : CommandData
    {
        [XmlAttribute("jumpUnit")]
        public string jumpUnit;
        [XmlAttribute("TransferId")]
        public int TransferId;

        public JumpCommandData()
        {
            commandType = EvtCommandType.JumpCell;
            jumpUnit = string.Empty;
            TransferId = 0;
        }
    }
    [Serializable]
    public class SetRotateSceneObjData : CommandData
    {
        [XmlAttribute("scenePath")]
        public string scenePath;
        [XmlAttribute("x")]
        public float x;
        [XmlAttribute("y")]
        public float y;
        [XmlAttribute("z")]
        public float z;
        public SetRotateSceneObjData()
        {
            commandType = EvtCommandType.RotateSceneObj;
            scenePath = string.Empty;
        }
    }
    /// <summary>
    /// 设置个体位置
    /// </summary>
    [Serializable]
    public class SetPositionCommandData : CommandData
    {
        [XmlAttribute("unitName")]
        public string unitName;
        [XmlAttribute("posX")]
        public float posX;
        [XmlAttribute("posY")]
        public float posY;
        [XmlAttribute("posZ")]
        public float posZ;

        public SetPositionCommandData()
        {
            commandType = EvtCommandType.SetPosition;
            unitName = string.Empty;
        }
    }

    /// <summary>
    /// 设置
    /// </summary>
    [Serializable]
    public class SetUnitAIActiveCommandData : CommandData
    {
        [XmlAttribute("active")]
        public bool active;
        [XmlAttribute("objectId")]
        public string objectId;

        public SetUnitAIActiveCommandData()
        {
            commandType = EvtCommandType.SetUnitAIActive;
            objectId = string.Empty;
        }
    }

    /// <summary>
    /// 设置对话选择栏
    /// </summary>
    [Serializable]
    public class PlayPlotCommandData : CommandData
    {
        [XmlAttribute("plotId")]
        public int plotId;
        [XmlAttribute("openLoading")]
        public bool openLoading = true;
        public PlayPlotCommandData()
        {
            commandType = EvtCommandType.PlayPlot;
        }
    }

    /// <summary>
    /// 设置对话选择栏
    /// </summary>
    [Serializable]
    public class ShowTalkCommandData : CommandData
    {
        [XmlAttribute("talkId")]
        public int talkId;
        public ShowTalkCommandData()
        {
            commandType = EvtCommandType.ShowTalk;
        }
    }

    /// <summary>
    /// 激活单个事件
    /// </summary>
    [Serializable]
    public class ActiveTriggerCommandData : CommandData
    {
        [XmlAttribute("triggerId")]
        public string triggerId;
        [XmlAttribute("active")]
        public bool active;

        public ActiveTriggerCommandData()
        {
            commandType = EvtCommandType.ActiveTrigger;
            triggerId = string.Empty;
        }
    }
   

    [Serializable]
    public class DelateStoryCommandData : CommandData
    {
        [XmlAttribute("storyId")]
        public string storyId;
        public DelateStoryCommandData()
        {
            commandType = EvtCommandType.DelateStory;
            storyId = string.Empty;
        }
    }
}
